package com.zcl.javaClassAndObject.collection.typeUnknown8_2_1;

import java.util.Hashtable;

/**
 * @Description:
 * @author: zcl
 * @date: 2021/12/13  16:42
 */
class Groundhog2 {
    int ghNumber;
    Groundhog2(int n) { ghNumber = n; }
    @Override
    public int hashCode() { return ghNumber; }
    @Override
    public boolean equals(Object o) {
        return (o instanceof Groundhog2)
                && (ghNumber == ((Groundhog2)o).ghNumber);
    }
}

class Prediction {
    boolean shadow = Math.random() > 0.5;
    @Override
    public String toString() {
        if(shadow) {
            return "Six more weeks of Winter!";
        } else {
            return "Early Spring!";
        }
    }
}



public class SpringDetector2 {
    public static void main(String[] args) {
        Hashtable ht = new Hashtable();
        for(int i = 0; i < 10; i++) {
            ht.put(new Groundhog2(i),new Prediction());
        }
        System.out.println("ht = " + ht + "\n");
        System.out.println(
                "Looking up prediction for groundhog #3:");
        Groundhog2 gh = new Groundhog2(3);
        if(ht.containsKey(gh)) {
            System.out.println((Prediction)ht.get(gh));
        }
    }

}
